package com.example.finalapplication;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import java.util.List;
import java.util.Map;

/*public class AnimalAdapter extends RecyclerView.Adapter<AnimalAdapter.ViewHolder> {
     private ItemData[] listdata;

    public AnimalAdapter(ItemData[] listdata) {
        this.listdata = listdata;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return null;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {

    }

    @Override
    public int getItemCount() {
        return listdata.length;
    }


    public static class ViewHolder extends RecyclerView.ViewHolder {
        public TextView name;
        public TextView Ename;
        public TextView Ke;
        public TextView Gang;
        public ConstraintLayout constraintLayout;

        public ViewHolder(View itemView) {
            super(itemView);
            this.name = (TextView) itemView.findViewById(R.id.name);
            this.Ename = (TextView)itemView.findViewById(R.id.Ename);
            this.Ke = (TextView)itemView.findViewById(R.id.Ke);
            this.Gang = (TextView)itemView.findViewById(R.id.Gang);
            this.constraintLayout = (ConstraintLayout) itemView.findViewById(R.id.cons);
        }*/

public class AnimalAdapter extends ArrayAdapter {
  public AnimalAdapter(@NonNull Context context, int resource, @NonNull List objects) {
        super(context, resource, objects);
    }

        @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        View itemView = convertView;
        if (itemView == null) {
            itemView = LayoutInflater.from(getContext()).inflate(R.layout.animal_item,
                    parent,
                    false);

        }

        Map<String, String> map = (Map<String, String>) getItem(position);

        TextView name = (TextView)itemView.findViewById(R.id.name);
        TextView Ename = (TextView)itemView.findViewById(R.id.Ename);
        TextView Ke = (TextView)itemView.findViewById(R.id.Ke);
        TextView Gang = (TextView)itemView.findViewById(R.id.Gang);

        name.setText("中文名"+ map.get("name"));
        Ename.setText("外文名"+ map.get("Ename"));
        Ke.setText("科"+ map.get("Ke"));
        Gang.setText("纲"+ map.get("Gang"));

        return itemView;
    }


}
